

var port = 2004;
var hostname = 'localhost';

//引入内置http模块
var http = require('http');


var url = require('url');

//commonJS规范引入模块
var msg = require('./module.js')
console.log(msg);
// var {msg,title} = msg;
// console.log(msg,title);

//创建HTTP服务，起服务
var server = http.createServer((req, res) => {

    const { pathname, query } = url.parse(req.url);  //格式化请求路径  获取pathname 和query  pathname就是地址栏？问号前面的东西，不包括localhost和端口；query就是地址栏？问号后面的东西

    // console.log(pathname);
    // console.log(query);


    res.writeHead(200, { "content-type": "text/html;charset=utf8" });//请求头防止中文乱码



    res.write(`${msg.msg}-----${msg.title}`);



    res.end();

}).listen(port, hostname, () => {
    console.log(`my node server is running at htttp://${hostname}:${port}`);
})